package com.msmall.community.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.msmall.base.util.ConstantDB;
import com.msmall.community.ApplicationManager;
import com.msmall.community.common.model.RankRule;
import com.msmall.community.common.service.RankRuleManager;

public class RankTag extends TagSupport{

	private static final long serialVersionUID = -6925671180485651621L;
	
	private String levels;

	public int doStartTag() throws JspException {
		return (SKIP_BODY);
	}

	public int doEndTag() throws JspException {
		JspWriter writer = pageContext.getOut();
		String ctx = ((HttpServletRequest)pageContext.getRequest()).getContextPath();
		try{
			writer.print(getRankName());
		}catch(Exception e){
			
		}
		return (SKIP_BODY);
	}
	
	private String getRankName(){
		RankRuleManager ruleManager = (RankRuleManager)ApplicationManager.appContext.getBean("rankRuleManager");
		String rankName = "";
		try {
			RankRule rule = ruleManager.getRankRule(Integer.valueOf(levels));
			rankName = rule.getRankName();
		} catch (Exception e) {
			try {
				ruleManager.getRankRule(ConstantDB.LEVELS_INIT).getRankName();
			} catch (Exception e1) {
			}
		}
		return rankName;
	}
	
	public String getLevels() {
		return levels;
	}

	public void setLevels(String levels) {
		this.levels = levels;
	}
	
}
